package com.sopt.view;

import java.util.List;

import com.sopt.friends.R;
import com.sopt.friends.vo.FriendsBasicMember;
import com.sopt.friends.vo.FriendsCommonItem;
import com.sopt.friends.vo.FriendsPhone;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class GroupMemberAdapter extends BaseAdapter {
	
	private Context mContext;
	private List<FriendsBasicMember> mMemberList;
	private int mLayout;
	
	public GroupMemberAdapter(Context context, int layout, List<FriendsBasicMember> inputList) {
		mContext = context;
		mMemberList = inputList;
		mLayout = layout;
	}

	public int getCount() {
		return mMemberList.size();
	}

	public Object getItem(int position) {
		return mMemberList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		FriendsBasicMember mHomeMemberRow = mMemberList.get(position);
		LayoutInflater inflate = LayoutInflater.from(mContext);
		
		View mCurrentView = inflate.inflate(mLayout, parent, false);
		
		TextView mTextView = (TextView)mCurrentView.findViewById(R.id.homeMemberRowName);
		TextView mTextViewDate = (TextView)mCurrentView.findViewById(R.id.homeMemberRowDate);
		ImageView mImageView = (ImageView)mCurrentView.findViewById(R.id.homeMemberRowImage);
		TextView mRankingView = (TextView)mCurrentView.findViewById(R.id.homeMemberRowRanking);
		
		TextView mNumberView = (TextView)mCurrentView.findViewById(R.id.homeMemberRowNumber);
		
		if( mTextView != null )	mTextView.setText( mHomeMemberRow.getDisplayname() );
		if( mTextViewDate != null ) {
			String currentRegdate = "";
			if(mHomeMemberRow.getRegdate().length()>0 && !mHomeMemberRow.getRegdate().equals("0")){
				currentRegdate = mHomeMemberRow.getRegdate();
			}
			
			mTextViewDate.setText( mCurrentView.getResources().getText(R.string.textRegdate) +" : "+currentRegdate );
		}
		if( mImageView != null ){
			if(mHomeMemberRow.getPhoto()!=null)
				mImageView.setImageBitmap(mHomeMemberRow.getPhoto());
			else
				mImageView.setImageResource(R.drawable.noimage);
		}
		if( mRankingView != null){
			mRankingView.setText(String.valueOf(position+1)+".");
		}
		
		if(mNumberView != null){
			String phoneList = "";
			for(FriendsPhone curPhone:mHomeMemberRow.getPhoneList()){
				phoneList+= curPhone.getPhonenumber()+"\n";
			}
			mNumberView.setText(phoneList);
			
		}
		
		return mCurrentView;
	}

}
